package com.ornate.dbre;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;

import org.hibernate.cfg.Configuration;
import org.hibernate.dialect.Dialect;
import org.hibernate.tool.hbm2ddl.DatabaseMetadata;
import org.hibernate.tool.hbm2ddl.SchemaUpdate;

public class Engineer {

	private static Dialect dialect;

	public static void main(String[] args) throws Exception {
		//		Configuration cfg = new Configuration();

		/*Properties properties = new Properties();
		properties.load(Engineer.class.getResourceAsStream("/hibernate.properties"));
		cfg.setProperties(properties);
		
		System.out.println(cfg.getProperties());*/

		Class.forName("com.mysql.jdbc.Driver");
		Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mis3", "root", "root");
		conn.setCatalog("mis3");
		
		DatabaseMetaData dbmd = conn.getMetaData();

		System.out.println(dbmd.getDatabaseProductName());
		System.out.println(dbmd.getDatabaseProductVersion());
		System.out.println(dbmd.getDriverName());
		System.out.println(dbmd.getDriverVersion());
		System.out.println(dbmd.getExtraNameCharacters());
		System.out.println(dbmd.getIdentifierQuoteString());
		System.out.println(dbmd.getJDBCMajorVersion());
		System.out.println(dbmd.getJDBCMinorVersion());
		System.out.println(dbmd.getMaxColumnsInGroupBy());

		System.out.println("数据库已知的用户: " + dbmd.getUserName());
		System.out.println("数据库的系统函数的逗号分隔列表: " + dbmd.getSystemFunctions());
		System.out.println("数据库的时间和日期函数的逗号分隔列表: " + dbmd.getTimeDateFunctions());
		System.out.println("数据库的字符串函数的逗号分隔列表: " + dbmd.getStringFunctions());
		System.out.println("数据库供应商用于 'schema' 的首选术语: " + dbmd.getSchemaTerm());
		System.out.println("数据库URL: " + dbmd.getURL());
		System.out.println("是否允许只读:" + dbmd.isReadOnly());
		System.out.println("数据库的产品名称:" + dbmd.getDatabaseProductName());
		System.out.println("数据库的版本:" + dbmd.getDatabaseProductVersion());
		System.out.println("驱动程序的名称:" + dbmd.getDriverName());
		System.out.println("驱动程序的版本:" + dbmd.getDriverVersion());

		System.out.println();
		System.out.println("数据库中使用的表类型");
		ResultSet rs = dbmd.getTableTypes();
		while (rs.next()) {
			System.out.println(rs.getString(1));
		}
		rs.close();

		System.out.println();
		System.out.println("数据库中使用的表类型");
		ResultSet schemas = dbmd.getCatalogs();
		while (schemas.next()) {
			System.out.println(schemas.getString(1));
		}
		rs.close();
		
		
		System.out.println();
		System.out.println("数据库中使用的表类型");
		ResultSet rs3 = dbmd.getTables("mis3", "", "", null);
		while (rs3.next()) {
			System.out.println(rs3.getObject(1));
			System.out.println(rs3.getObject(2));
			System.out.println(rs3.getObject(3));
			System.out.println(rs3.getObject(4));
			System.out.println(rs3.getObject(5));
			System.out.println();
		}
		rs.close();

		/*dialect = Dialect.getDialect(cfg.getProperties());

		DatabaseMetadata db = new DatabaseMetadata(conn, dialect);
		

		System.out.println(db.getTableMetadata("t_s_p_user", "mis3", "", false));*/

		/*for (Iterator iterator = cfg.getTableMappings(); iterator.hasNext();) {
			Table type = (Table) iterator.next();
			System.out.println(type.getName());
		}*/
		
	}

}
